/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package coalescent.br;

import coalescent.data.PopGenData;
import coalescent.model.PopGenModel;

import commons.core.Statistic;

/**
 * Describes an event that a sample configuration (statistic) could experience during a backward
 * recursion. This event class captures the type of the population genetic event and the resulting
 * ancestral configuration.
 * It describes the context that a population genetic event of type {@code EventType} affects a
 * sample configuration to produce a different sample configuration when the time is viewed
 * forwards. The time scale could be either discrete, in generations or continuous, suitable scaled.
 *
 * @param <E>
 * @param <M>
 * @param <D>
 * @param <S>
 * @param <R>
 * @author Susanta Tewari
 * @version 1.0 Oct 6, 2010
 */
public class BREvent<E extends Enum<E>, M extends PopGenModel<E>, D extends PopGenData<?, E, M, D>,
                     S extends Statistic<D, S>, R extends BRSPopGen<?, ?, E, M, D, S, R>> {

    /** Field description */
    private final R recursionConfig;

    /** Field description */
    private final E eventType;

    /**
     * Creates an event object based on the specified event type that acts on the specified sample
     * configuration.
     *
     * @param recursionConfig the sample configuration to be affected
     * @param type the type of the population genetic event affecting the sample configuration
     */
    public BREvent(R recursionConfig, E type) {

        this.recursionConfig = recursionConfig;
        this.eventType       = type;
    }

    /**
     * The sample configuration on which the event took place to produce a different sample
     * configuration.
     *
     * @return the sample configuration on which the event took place
     */
    public R getConfig() {
        return recursionConfig;
    }

    /**
     * The type of the population genetic event corresponding to this event object.
     *
     * @return the type of the population genetic event corresponding to this event object
     */
    public E getType() {
        return eventType;
    }

    /**
     * A textual description of this event object with information on the affected sample
     * configuration affected and the type of the population genetic event. It does not end with a
     * new line character.
     *
     * @return textual description of this event object
     */
    @Override
    public String toString() {

        return new StringBuilder().append("[").append(eventType).append(",").append(
            recursionConfig).append("]").toString();
    }
}
